package com.hn.zhijian.base.data.db;

import com.hn.zhijian.base.data.common.DbContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;


/**
 * @program: carl-main
 * @description: 默认数据库
 * @author: carl
 * @create: 2019-11-17 20:21
 **/
@Component
@Slf4j
@Aspect
@ConfigurationProperties(prefix = "spring.datasource.druid.sys-db")
public class DBDefault extends AbstractDataSource {

    /**
     * 自动切换数据源
     */
    @Override
    @Pointcut("execution(* com.hn.zhijian.system.service..*.*(..))")
    public void pointcutFunction() {
//        log.info("切换到默认数据库 com.hn.zhijian.system.service");
    }

    /**
     * 切面
     */
    @Override
    @Before("pointcutFunction()")
    public void beforeFunction() {
        //切换数据库
        DbContextHolder.setDbType("sys-db");
    }

    @Override
    public String dbName() {
        return "sys-db";
    }
}
